<?php
require_once '../libs/app.config.php';
session_start();
if($_SESSION['LoginId'] == false){
	header("Location:login.php");
}
$tpn = new Page();
//分类列表
$sql="select cat.cat_name,art.id,art.title,art.add_time,art.is_recommend,art.is_show ,art.sort_order from article_cat as cat,articles as art where cat.id=art.cat_id order by art.id desc";
$query=$tpm->query($sql);
$totals=$tpm->num_rows($query);
	$tpn->pageft($totals,10);
	$result=$tpm->query($sql." limit ".$tpn->getfirstcount().",10");

while($rows=$tpm->fetch_array($result))
{

$cat_list[]=array('cat_name'=>$rows['cat_name'],
			     'id'=>$rows['id'],
				 'title'=>$rows['title'],
				 'add_time'=>$rows['add_time'],
				 'is_recommend'=>$rows['is_recommend'],
				 'sort_order'=>$rows['sort_order'],
				 'is_show'=>$rows['is_show']);
}

//多项删除
if($_POST['submit'])
{
	if(!empty($_POST['check']))
	{
		$array=$_POST['check'];
		$arr=implode(',',$array);
		$id=explode(',',$arr);
		$size=count($id);
		for($j=0;$j<$size;$j++)
		{
			$sql="delete from articles where id='".$id[$j]."'";
			$query=$tpm->query($sql);
			if($query>0)
			echo "<script>alert('删除成功');history.back();</script>";
		}
	}
}


//单项删除
if($_POST['delid'])
{
  $sql="delete from articles where id='".$_POST['delid']."'";
  $query=$tpm->query($sql);
  if($query>0)
  echo "1";
  else
  echo "0";
}

require_once(INCLUDE_PATH.'template.inc.php');  //模板类及对象$tpl的加载
    $tpl->assign("cat_list",$cat_list);
	$tpl->assign('pages',$tpn->getpagenav());
	$tpl->display("news_list.html");
?>